# Contributor: @ifurther <55025025+ifurther@users.noreply.github.com>

_realname=pipenv
pkgbase=mingw-w64-python-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_realname}
pkgver=2023.9.1
pkgrel=1
pkgdesc="Python Development Workflow for Humans."
url="https://pipenv.pypa.io"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('spdx:MIT')
depends=(
    "${MINGW_PACKAGE_PREFIX}-python"
    "${MINGW_PACKAGE_PREFIX}-python-certifi"
    "${MINGW_PACKAGE_PREFIX}-python-setuptools"
    "${MINGW_PACKAGE_PREFIX}-python-virtualenv"
    "${MINGW_PACKAGE_PREFIX}-python-virtualenv-clone"
)
makedepends=(
    "${MINGW_PACKAGE_PREFIX}-python-build"
    "${MINGW_PACKAGE_PREFIX}-python-installer"
    "${MINGW_PACKAGE_PREFIX}-python-wheel"
)
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('f6360a83fcb137a20ea87c084d0cfca5ad85359fe2ea110849032d80bc7b0011')

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"

  _PIPENV_COMPLETE=bash_source ${pkgdir}${MINGW_PREFIX}/bin/pipenv | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/pipenv"
  _PIPENV_COMPLETE=zsh_source  ${pkgdir}${MINGW_PREFIX}/bin/pipenv | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_pipenv"
  /usr/bin/env _PIPENV_COMPLETE=fish_source ${pkgdir}${MINGW_PREFIX}/bin/pipenv | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/pipenv.fish"
}
